#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import config
import MySQLEngine
# from questiontemplate import question_program_dictionary

from srf_log import init_log, logger

class DBInterface(object):
    def __init__(self):
        #
        # #stock-news
        # self.old_news_data = MySQLEngine.MySQLEngine()
        # self.old_news_data.connect(db_host=config.mysql_news_host,
        #                       db_port=config.mysql_port,
        #                       db_user=config.mysql_user,
        #                       db_pwd=config.mysql_pwd,
        #                       db=config.mysql_stock_news_db)

        # stock_base (luc-rds)
        self.stock_base = MySQLEngine.MySQLEngine()
        self.stock_base.connect(db_host=config.mysql_stockbase_host,
                               db_port=config.mysql_port,
                               db_user=config.mysql_stockbase_user,
                               db_pwd=config.mysql_stockbase_pwd,
                               db=config.mysql_stockbase_db)

        print('__init__ DBInterface')


def _init():
    global _global_dict
    _global_dict = {}

def set_value(name, value):
    _global_dict[name] = value

def get_value(name, defValue=None):
    try:
        return _global_dict[name]
    except KeyError:
        return defValue

def get_keys():
    if '_global_dict' not in locals().keys():
        return []
    return _global_dict.keys()

def load_dbinterface():
    _global_dict['dbinterface'] = DBInterface()



def init_load():
    load_dbinterface()



